import base64
from Crypto.Cipher import PKCS1_v1_5
from Crypto import Random
from Crypto.PublicKey import RSA


def encrypt(content):
    """
    用公钥加密
    :param content: 加密的字符串
    :return:
    """
    # TODO PRIVE_KEY java端给的公钥
    private_key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxK6fwC/RohZblHThfWVdwTWE7sk+smjJUD2KDWLVhTiCo20z8DVqLfQxCcatA60FQL6GoKcZC14rXi3rT9ufcazLY0/2PkbKk2YpNadv4R69stpm+o32s1TMijjbhD/cNSBq+KQANGT7HeNbJV0J68pZsPQ4hcS8jGwpae2bt/ALCtSinU4squfH1Qa/WkV63gJ08E//elKOS8LHMNlR7tcj5CcKkJrXHSSyC7LdWc6mDzU4lBRY5PDXHHOVieOxUwh4ew+1NITO73StrOVBEzqrgYBeflY6PrhTlZFset86zyBiUHRDFunJEahCjsETDJRtvPTSbMmA84oT0qQ+7QIDAQAB'
    key = RSA.importKey(base64.b64decode(private_key))
    cipher = PKCS1_v1_5.new(key)
    return base64.b64encode(cipher.encrypt(str(content).encode(encoding='utf-8'))).decode('utf-8')


if __name__ == '__main__':
    a = encrypt(123456)
    print(a)
